<template>
	<view class="">
		<u-navbar :is-back="true" title="新增学员" back-icon-color="#ffffff" :background="{backgroundColor:'#E62131'}"
			title-color="#ffffff"></u-navbar>
		<view class="clasforms">
			<u-form :model="form" ref="uForm" label-width="150rpx">
				<u-form-item label="学员姓名"><u-input v-model="form.name" /></u-form-item>
				<u-form-item label="学员电话"><u-input v-model="form.phone" :maxlength="11" /></u-form-item>
				<u-form-item label="选择校区">
					<u-input v-model="texts" type="select" :border="false" @click="seltishow = true" />
				</u-form-item>
				<u-form-item label="备注"><u-input v-model="form.remarks" /></u-form-item>
			</u-form>
		</view>
		<u-action-sheet :list="soltList" v-model="seltishow" @click="actionSheetCallback"></u-action-sheet>

		<view class="bneads w-btn-fixed">
			<div class="btnlst fliexs space_between">
				<view class="btn_left right" @click="endkecheng">
					保存
				</view>
			</div>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dateshow: false,
				seltishow: false,
				coachshow: false,
				soltList: [],
				texts:"",
				form: {
					name: '',
					phone: '',
					campusId: '',
					remarks: '',
				},
				usersparms: {
					limit: 3000,
					page: 1,
					keyword: "",
					roleId: 2,
				},
			}
		},
		onLoad(option) {
			if(option.form){
				this.form = JSON.parse(option.form)
			}
			this.listNotPageApi()
		},
		methods: {
			actionSheetCallback(index){
				this.texts =  this.soltList[index].name
				this.form.campusId = this.soltList[index].id
			},
			endkecheng() {
				uni.$api.common.addstudentinfo(this.form).then((res) => {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					setTimeout(() => {
						uni.navigateBack({
							delta: 1,
						})
					}, 2000)
				});
			},
			// 获取校区
			listNotPageApi() {
				uni.$api.common.listNotPage().then((res) => {
					res.result.forEach((item) => {
						item.text = item.name
					})
					this.soltList = res.result
					if(this.form.id){
						this.soltList.forEach((item)=>{
							if(item.id == this.form.campusId){
								this.texts = item.name
							}
						})
					}
				});
			},
			nSheetCallback(index) {
				this.parms.campusId = this.soltList[index].id
				this.form.texts = this.soltList[index].name
			},
		}
	};
</script>
<style lang="scss">
	.clasforms {
		padding: 20rpx;
	}

	.btnlst {
		// margin-top: 350rpx;

		.btn_left {
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			color: #b1b1b1;
			border: 1rpx solid #e1e1e1;
		}

		.right {
			background-color: #E62131;
			color: #ffffff;
		}
	}

	.bgfenge {
		width: 100%;
		height: 10rpx;
		background-color: #f4f4f4;
	}

	.padingist {
		padding: 10rpx 30rpx 120rpx;
	}

	.topps {
		color: #b1b1b1;
		padding: 20rpx 0;
	}
</style>